$(function () {

    function Func() {
        // 轮播图区块
        this.villaBanneUl = $('.villa-banner .villa-banner-bg ul');
        this.villaBanneLis = $('.villa-banner .villa-banner-bg ul li');
        this.villaBanneLiWidth = $('.villa-banner .villa-banner-bg ul li').width();
        // 左右按钮
        this.villaBanneLeftBtn = $('.villa-banner .banner-btn .banner-btn-left')
        this.villaBanneRightBtn = $('.villa-banner .banner-btn .banner-btn-right')
        this.villaBanneTimer = null;
        this.villaBanneIndex = 0;
        this.villaBannerInpDestination = $('.villa-banner-form .banner-inp-destination');
        this.villaBannerInpName = $('.villa-banner-form .banner-inp-name');
        this.villaBannerInpPhone = $('.villa-banner-form .banner-inp-phone');
        this.villaBannerBtn = $('.villa-banner-form .villa-banner-form-content button');
        // 产品区块 tab选项卡
        this.productNavUl = $('.product .product-bottom-nav ul');
        this.productContents = $('.product .product-bottom-content');
        // 趣墅优品区块 tab选项卡
        this.youpinNavul = $('.youpin .youpin-bottom .product-nav-right ul');
        this.youpinContents = $('.youpin .youpin-bottom-content');
        // 案例攻略区块 轮播图
        this.strategyBannerUl = $('.strategy .strategy-banner ul');
        this.strategyBannerLis = $('.strategy .strategy-banner ul li');
        this.strategyBannerLiWidth = $('.strategy .strategy-banner ul li').width();
        this.strategyBannerPointOl = $('.strategy .strategy-point ol');
        this.strategyBannerPointLis = $('.strategy .strategy-point ol li');
        this.strategyBannerTimer = null;
        this.strategyBannerIndex = 0;
        this.strategyBannerCount = 0
        // 底部大图片区块
        this.footInpDestination = $('.foot-img .foot-inp-destination');
        this.footInpName = $('.foot-img .foot-inp-name');
        this.footInpPhone = $('.foot-img .foot-inp-phone');
        this.footBtn = $('.foot-img .foot-btn');
    }
    // 轮播图区块
    Func.prototype.villaBanneAutoPlay = function () {
        var _this = this;
        this.villaBanneTimer = setInterval(function () {
            _this.villaBanneIndex++;
            if (_this.villaBanneIndex > _this.villaBanneLis.length - 1) {
                _this.villaBanneIndex = 1;
                _this.villaBanneUl.css('left', 0);
            }
            _this.villaBanneUl.stop().animate({ left: - (_this.villaBanneIndex * _this.villaBanneLiWidth) }, 2000);
        }, 3000)
    }
    // 案例攻略区块
    Func.prototype.strategyBanneAutoPlay = function () {
        var _this = this;
        this.strategyBannerTimer = setInterval(function () {
            _this.strategyBannerIndex++;
            if (_this.strategyBannerIndex > _this.strategyBannerLis.length - 1) {
                _this.strategyBannerIndex = 1;
                _this.strategyBannerUl.css('left', 0);
            }
            _this.strategyBannerUl.stop().animate({ left: -(_this.strategyBannerIndex * _this.strategyBannerLiWidth) + 'px' }, 1000);
            _this.strategyBannerCount++;
            if (_this.strategyBannerCount > _this.strategyBannerPointLis.length - 1) {
                _this.strategyBannerCount = 0;
            }
            _this.strategyBannerPointLis.eq(_this.strategyBannerCount).addClass('active').siblings().removeClass('active');
        }, 2500)
    }

    Func.prototype.addEvent = function () {
        var _this = this;
        // 轮播图区块
        this.villaBanneLeftBtn.on('click', function () {
            _this.villaBanneIndex--;
            if (_this.villaBanneIndex < 0) {
                _this.villaBanneIndex = _this.villaBanneLis.length - 1;
                _this.villaBanneUl.css('left', -(_this.villaBanneIndex * _this.villaBanneLiWidth));
            }
            _this.villaBanneUl.stop().animate({ left: - (_this.villaBanneIndex * _this.villaBanneLiWidth) }, 1000);
            clearInterval(_this.villaBanneTimer);
            _this.villaBanneAutoPlay();
        })
        this.villaBanneRightBtn.on('click', function () {
            _this.villaBanneIndex++;
            if (_this.villaBanneIndex > _this.villaBanneLis.length - 1) {
                _this.villaBanneIndex = 1;
                _this.villaBanneUl.css('left', 0);
            }
            _this.villaBanneUl.stop().animate({ left: - (_this.villaBanneIndex * _this.villaBanneLiWidth) }, 1000);
            clearInterval(_this.villaBanneTimer);
            _this.villaBanneAutoPlay();
        })
        this.villaBannerBtn.on('click', function () {
            var inp1 = _this.villaBannerInpDestination.val();
            var inp2 = _this.villaBannerInpName.val();
            var inp3 = _this.villaBannerInpPhone.val();
            if (inp1.length == 0) {
                alert('请填写目的地！');
                return;
            }
            if (inp2.length == 0) {
                alert('请填写正确的联系人姓名！');
                return;
            }
            if (inp3.length == 0) {
                alert('请填写正确的联系电话！');
                return;
            }
            alert('定制成功！我们将尽快与您联系！');
        })
        this.villaBanneLis.on('mouseenter mouseleave', function (event) {
            var origType = event.handleObj.origType;
            if (origType == 'mouseenter') {
                clearInterval(_this.villaBanneTimer);
            } else if (origType == 'mouseleave') {
                _this.villaBanneAutoPlay();
            }
        })
        // 案例攻略区块
        this.strategyBannerPointOl.on('click', 'li', function () {
            clearInterval(_this.strategyBannerTimer);
            _this.strategyBannerIndex = $(this).index();
            _this.strategyBannerCount = $(this).index();
            _this.strategyBannerUl.stop().animate({ left: -($(this).index() * _this.strategyBannerLiWidth) + 'px' }, 1000);
            _this.strategyBannerPointLis.eq($(this).index()).addClass('active').siblings().removeClass('active');
            _this.strategyBanneAutoPlay();
        })
        this.strategyBannerLis.on('mouseenter mouseleave', function (event) {
            var origType = event.handleObj.origType;
            if (origType == 'mouseenter') {
                clearInterval(_this.strategyBannerTimer);
            } else if (origType == 'mouseleave') {
                _this.strategyBanneAutoPlay();
            }
        })
        // 产品区块 tab选项卡
        this.productNavUl.on('mouseenter', 'li', function () {
            $(this).addClass('active').siblings().removeClass('active');
            _this.productContents.eq($(this).index()).addClass('active').siblings().removeClass('active');
        })
        // 趣墅优品区块 tab选项卡
        this.youpinNavul.on('mouseenter', 'li', function () {
            $(this).addClass('active').siblings().removeClass('active');
            _this.youpinContents.eq($(this).index()).addClass('active').siblings().removeClass('active');
        })
        // 底部大图片区块
        this.footBtn.on('click', function () {
            var inp1 = _this.footInpDestination.val();
            var inp2 = _this.footInpName.val();
            var inp3 = _this.footInpPhone.val();
            if (inp1.length == 0) {
                alert('请填写目的地！');
                return;
            }
            if (inp2.length == 0) {
                alert('请填写正确的联系人姓名！')
                return;
            }
            if (inp3.length == 0) {
                alert('请填写正确的联系电话！')
                return;
            }
            alert('定制成功！我们将尽快与您联系！')
        })


    }

    Func.prototype.init = function () {
        this.villaBanneAutoPlay();
        this.strategyBanneAutoPlay();
        this.addEvent();
    }
    console.log(new Func());
    new Func().init();










})